<template>
    <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
    mixins: [resize],
    props: {
      lines:{
        type:Array/*,
        default:["1","2","3"]*/
      },
      linesTwo:{
        type:Array
        /*default:[
          {value:1,
            name:"1"},
          {value:2,
            name:"2"},
          {value:3,
            name:"3"}
        ]*/
      },
        className: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '100%'
        },
        height: {
            type: String,
            default: '300px'
        }
    },
    data () {
        return {
            chart: null
        }
    },
    mounted () {
        this.$nextTick(() => {
            this.initChart(this.lines,this.linesTwo)
        })
    },
    beforeDestroy () {
        if (!this.chart) {
            return
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        initChart (line,lineTwo) {
            this.chart = echarts.init(this.$el, 'macarons')

            this.chart.setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: '{b} : {c}'
                    // formatter: '{a} <br/>{b} : {c} ({d}%)'
                },
                legend: {
                    left: 'center',
                    bottom: '10',
                    data: line,
                },
                series: [
                    {
                        // name: 'WEEKLY WRITE ARTICLES',
                        type: 'pie',
                        // roseType: 'radius',   //玫瑰图
                        radius: [15, 95],
                        center: ['50%', '38%'],
                        data: lineTwo,
                        animationEasing: 'cubicInOut',
                        animationDuration: 2600
                    }
                ]
            })
        }
    }
}
</script>
